const DataBaseConfig = require('../data_base_config').sequelize();

const Admin = DataBaseConfig.import('../model/admin');

Admin.sync();

module.exports = {
  findAll(number, size) {
    return Admin.findAndCount({
      offset: (number - 1) * size,
      limit: +size,
      order: [['id', 'DESC']],
    });
  },
  findById(id) {
    return Admin.findById(id);
  },
  findByUserNameAndPwd(userName, pwd) {
    return Admin.findOne({ where: { user_name: userName, pass_word: pwd }, raw: true });
  },
  update(admin) {
    return Admin.update(admin, { where: { id: admin.id } });
  },
  create(admin) {
    return Admin.create(admin);
  },
  delete(admin) {
    return Admin.destroy({ where: { id: admin.id } });
  },
};
